/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package LDVH.ihm;

import LDVH.factories.LivreFactory;
import LDVH.factories.OutilsFactory;
import LDVH.itf.IAnalyseGraphe;
import LDVH.itf.ILivre;
import LDVH.itf.ILoad;
import LDVH.itf.ISave;
import LDVH.itf.ISection;
import java.awt.Dimension;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import java.util.ArrayList;
import java.util.List;
import javax.swing.Box;
import javax.swing.DefaultComboBoxModel;
import javax.swing.DefaultListModel;
import javax.swing.JComboBox;
import javax.swing.JFileChooser;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JTextField;
import javax.swing.filechooser.FileNameExtensionFilter;

/**
 *
 * @author daniele
 */
public class LdvhIHM extends javax.swing.JFrame {

    /**
     * Creates new form NewJFrame
     */
    public LdvhIHM() {
        graphViewer = new LdvhGraphViewer(new Dimension(486, 627));
        initComponents();
        this.sectionPanel.setVisible(false);
        this.enchainementPanel.setVisible(false);
   }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        graphPanel = graphViewer.getPanel();
        editionPanes = new javax.swing.JLayeredPane();
        enchainementPanel = new javax.swing.JPanel();
        enchCondsPanel = new javax.swing.JPanel();
        enchAjoutCondBtn = new javax.swing.JButton();
        enchSupCondBtn = new javax.swing.JButton();
        enchCondList = new javax.swing.JList();
        enchSupprimerBtn = new javax.swing.JButton();
        enchAnnulerButton = new javax.swing.JButton();
        enchValiderButton = new javax.swing.JButton();
        enchDepartLabel = new javax.swing.JLabel();
        enchArrowLabel = new javax.swing.JLabel();
        enchArriveeLabel = new javax.swing.JLabel();
        sectionPanel = new javax.swing.JPanel();
        sectionValiderButton = new javax.swing.JButton();
        sectionAnnulerButton = new javax.swing.JButton();
        sectionInitialeCheck = new javax.swing.JCheckBox();
        sectionTextePanel = new javax.swing.JPanel();
        jScrollPane1 = new javax.swing.JScrollPane();
        sectionTexteTextArea = new javax.swing.JTextArea();
        sectionObjetsPanel = new javax.swing.JPanel();
        sectionAjoutObjetBtn = new javax.swing.JButton();
        sectionSupObjetBtn = new javax.swing.JButton();
        sectionObjList = new javax.swing.JList();
        sectionSupprimerBtn = new javax.swing.JButton();
        sectionNom = new javax.swing.JLabel();
        jMenuBar1 = new javax.swing.JMenuBar();
        livreMenu = new javax.swing.JMenu();
        creerButton = new javax.swing.JMenuItem();
        chargerButton = new javax.swing.JMenuItem();
        enregistrerButton = new javax.swing.JMenuItem();
        jSeparator1 = new javax.swing.JPopupMenu.Separator();
        analyserButton = new javax.swing.JMenuItem();
        jSeparator2 = new javax.swing.JPopupMenu.Separator();
        fermerLivreBtn = new javax.swing.JMenuItem();
        quitterButton = new javax.swing.JMenuItem();
        editerMenu = new javax.swing.JMenu();
        sectionsButton = new javax.swing.JMenuItem();
        enchainementsButton = new javax.swing.JMenuItem();
        generationMenu = new javax.swing.JMenu();
        genHTMLButton = new javax.swing.JMenuItem();
        genImprimableButton = new javax.swing.JMenuItem();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("LDVH");
        setMinimumSize(new java.awt.Dimension(830, 653));

        graphPanel.setPreferredSize(new java.awt.Dimension(486, 627));
        graphPanel.setSize(new java.awt.Dimension(486, 627));

        javax.swing.GroupLayout graphPanelLayout = new javax.swing.GroupLayout(graphPanel);
        graphPanel.setLayout(graphPanelLayout);
        graphPanelLayout.setHorizontalGroup(
            graphPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 486, Short.MAX_VALUE)
        );
        graphPanelLayout.setVerticalGroup(
            graphPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 0, Short.MAX_VALUE)
        );

        editionPanes.setBorder(javax.swing.BorderFactory.createEtchedBorder());
        editionPanes.setSize(new java.awt.Dimension(323, 623));

        enchCondsPanel.setBorder(javax.swing.BorderFactory.createTitledBorder("Conditions"));
        enchCondsPanel.setSize(new java.awt.Dimension(295, 185));

        enchAjoutCondBtn.setText("Ajouter");
        enchAjoutCondBtn.setMaximumSize(new java.awt.Dimension(108, 29));
        enchAjoutCondBtn.setMinimumSize(new java.awt.Dimension(108, 29));
        enchAjoutCondBtn.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                enchAjoutCondBtnActionPerformed(evt);
            }
        });

        enchSupCondBtn.setText("Supprimer");
        enchSupCondBtn.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                enchSupCondBtnActionPerformed(evt);
            }
        });

        enchCondList.setModel(new javax.swing.AbstractListModel() {
            String[] strings = { "Item 1", "Item 2", "Item 3", "Item 4", "Item 5" };
            public int getSize() { return strings.length; }
            public Object getElementAt(int i) { return strings[i]; }
        });

        javax.swing.GroupLayout enchCondsPanelLayout = new javax.swing.GroupLayout(enchCondsPanel);
        enchCondsPanel.setLayout(enchCondsPanelLayout);
        enchCondsPanelLayout.setHorizontalGroup(
            enchCondsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(enchCondList, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, enchCondsPanelLayout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(enchAjoutCondBtn, javax.swing.GroupLayout.PREFERRED_SIZE, 100, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(enchSupCondBtn)
                .addGap(30, 30, 30))
        );
        enchCondsPanelLayout.setVerticalGroup(
            enchCondsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, enchCondsPanelLayout.createSequentialGroup()
                .addComponent(enchCondList, javax.swing.GroupLayout.PREFERRED_SIZE, 126, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGroup(enchCondsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(enchSupCondBtn)
                    .addComponent(enchAjoutCondBtn, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
        );

        enchSupprimerBtn.setText("Supprimer");
        enchSupprimerBtn.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                enchSupprimerBtnActionPerformed(evt);
            }
        });

        enchAnnulerButton.setText("Annuler");
        enchAnnulerButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                enchAnnulerButtonActionPerformed(evt);
            }
        });

        enchValiderButton.setText("Valider");
        enchValiderButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                enchValiderButtonActionPerformed(evt);
            }
        });

        enchDepartLabel.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        enchDepartLabel.setText("depart");

        enchArrowLabel.setFont(new java.awt.Font("Lucida Grande", 1, 18)); // NOI18N
        enchArrowLabel.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        enchArrowLabel.setText("\u2193");

        enchArriveeLabel.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        enchArriveeLabel.setText("arrivée");

        javax.swing.GroupLayout enchainementPanelLayout = new javax.swing.GroupLayout(enchainementPanel);
        enchainementPanel.setLayout(enchainementPanelLayout);
        enchainementPanelLayout.setHorizontalGroup(
            enchainementPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(enchainementPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(enchainementPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(enchCondsPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addGroup(enchainementPanelLayout.createSequentialGroup()
                        .addComponent(enchSupprimerBtn)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 22, Short.MAX_VALUE)
                        .addComponent(enchAnnulerButton)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(enchValiderButton))
                    .addComponent(enchDepartLabel, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(enchArrowLabel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(enchArriveeLabel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addContainerGap())
        );
        enchainementPanelLayout.setVerticalGroup(
            enchainementPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(enchainementPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(enchDepartLabel)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(enchArrowLabel)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(enchArriveeLabel)
                .addGap(18, 18, 18)
                .addComponent(enchCondsPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 305, Short.MAX_VALUE)
                .addGroup(enchainementPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(enchValiderButton)
                    .addComponent(enchAnnulerButton)
                    .addComponent(enchSupprimerBtn))
                .addContainerGap())
        );

        sectionPanel.setPreferredSize(new java.awt.Dimension(323, 623));
        sectionPanel.setSize(new java.awt.Dimension(323, 623));

        sectionValiderButton.setText("Valider");
        sectionValiderButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                sectionValiderButtonActionPerformed(evt);
            }
        });

        sectionAnnulerButton.setText("Annuler");
        sectionAnnulerButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                sectionAnnulerButtonActionPerformed(evt);
            }
        });

        sectionInitialeCheck.setText("Section initiale");
        sectionInitialeCheck.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                sectionInitialeCheckActionPerformed(evt);
            }
        });

        sectionTextePanel.setBorder(javax.swing.BorderFactory.createTitledBorder("Texte"));

        sectionTexteTextArea.setColumns(20);
        sectionTexteTextArea.setRows(5);
        jScrollPane1.setViewportView(sectionTexteTextArea);

        javax.swing.GroupLayout sectionTextePanelLayout = new javax.swing.GroupLayout(sectionTextePanel);
        sectionTextePanel.setLayout(sectionTextePanelLayout);
        sectionTextePanelLayout.setHorizontalGroup(
            sectionTextePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jScrollPane1)
        );
        sectionTextePanelLayout.setVerticalGroup(
            sectionTextePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 183, Short.MAX_VALUE)
        );

        sectionObjetsPanel.setBorder(javax.swing.BorderFactory.createTitledBorder("Objets"));
        sectionObjetsPanel.setSize(new java.awt.Dimension(295, 185));

        sectionAjoutObjetBtn.setText("Ajouter");
        sectionAjoutObjetBtn.setMaximumSize(new java.awt.Dimension(108, 29));
        sectionAjoutObjetBtn.setMinimumSize(new java.awt.Dimension(108, 29));
        sectionAjoutObjetBtn.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                sectionAjoutObjetBtnActionPerformed(evt);
            }
        });

        sectionSupObjetBtn.setText("Supprimer");
        sectionSupObjetBtn.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                sectionSupObjetBtnActionPerformed(evt);
            }
        });

        sectionObjList.setModel(new javax.swing.AbstractListModel() {
            String[] strings = { "Item 1", "Item 2", "Item 3", "Item 4", "Item 5" };
            public int getSize() { return strings.length; }
            public Object getElementAt(int i) { return strings[i]; }
        });

        javax.swing.GroupLayout sectionObjetsPanelLayout = new javax.swing.GroupLayout(sectionObjetsPanel);
        sectionObjetsPanel.setLayout(sectionObjetsPanelLayout);
        sectionObjetsPanelLayout.setHorizontalGroup(
            sectionObjetsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(sectionObjList, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, sectionObjetsPanelLayout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(sectionAjoutObjetBtn, javax.swing.GroupLayout.PREFERRED_SIZE, 100, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(sectionSupObjetBtn)
                .addGap(30, 30, 30))
        );
        sectionObjetsPanelLayout.setVerticalGroup(
            sectionObjetsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, sectionObjetsPanelLayout.createSequentialGroup()
                .addComponent(sectionObjList, javax.swing.GroupLayout.PREFERRED_SIZE, 126, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(sectionObjetsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(sectionSupObjetBtn)
                    .addComponent(sectionAjoutObjetBtn, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
        );

        sectionSupprimerBtn.setText("Supprimer");
        sectionSupprimerBtn.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                sectionSupprimerBtnActionPerformed(evt);
            }
        });

        sectionNom.setFont(new java.awt.Font("Lucida Grande", 0, 18)); // NOI18N
        sectionNom.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        sectionNom.setText("nom section");
        sectionNom.setSize(new java.awt.Dimension(107, 22));

        javax.swing.GroupLayout sectionPanelLayout = new javax.swing.GroupLayout(sectionPanel);
        sectionPanel.setLayout(sectionPanelLayout);
        sectionPanelLayout.setHorizontalGroup(
            sectionPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(sectionPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(sectionPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(sectionTextePanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, sectionPanelLayout.createSequentialGroup()
                        .addComponent(sectionSupprimerBtn)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 15, Short.MAX_VALUE)
                        .addComponent(sectionAnnulerButton)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(sectionValiderButton)
                        .addGap(6, 6, 6))
                    .addComponent(sectionObjetsPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(sectionInitialeCheck, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(sectionNom, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addContainerGap())
        );
        sectionPanelLayout.setVerticalGroup(
            sectionPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(sectionPanelLayout.createSequentialGroup()
                .addComponent(sectionNom, javax.swing.GroupLayout.PREFERRED_SIZE, 33, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(sectionTextePanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(sectionObjetsPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(sectionInitialeCheck)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 102, Short.MAX_VALUE)
                .addGroup(sectionPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(sectionValiderButton)
                    .addComponent(sectionAnnulerButton)
                    .addComponent(sectionSupprimerBtn))
                .addContainerGap())
        );

        javax.swing.GroupLayout editionPanesLayout = new javax.swing.GroupLayout(editionPanes);
        editionPanes.setLayout(editionPanesLayout);
        editionPanesLayout.setHorizontalGroup(
            editionPanesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 328, Short.MAX_VALUE)
            .addGroup(editionPanesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addComponent(enchainementPanel, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
            .addGroup(editionPanesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, editionPanesLayout.createSequentialGroup()
                    .addGap(1, 1, 1)
                    .addComponent(sectionPanel, javax.swing.GroupLayout.DEFAULT_SIZE, 327, Short.MAX_VALUE)))
        );
        editionPanesLayout.setVerticalGroup(
            editionPanesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 627, Short.MAX_VALUE)
            .addGroup(editionPanesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addComponent(enchainementPanel, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
            .addGroup(editionPanesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(editionPanesLayout.createSequentialGroup()
                    .addContainerGap()
                    .addComponent(sectionPanel, javax.swing.GroupLayout.DEFAULT_SIZE, 615, Short.MAX_VALUE)
                    .addContainerGap()))
        );
        editionPanes.setLayer(enchainementPanel, javax.swing.JLayeredPane.DEFAULT_LAYER);
        editionPanes.setLayer(sectionPanel, javax.swing.JLayeredPane.DEFAULT_LAYER);

        jMenuBar1.setMinimumSize(new java.awt.Dimension(202, 22));
        jMenuBar1.setSize(new java.awt.Dimension(202, 22));

        livreMenu.setText("Livre");

        creerButton.setText("Créer nouveau");
        creerButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                creerButtonActionPerformed(evt);
            }
        });
        livreMenu.add(creerButton);

        chargerButton.setText("Charger");
        chargerButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                chargerButtonActionPerformed(evt);
            }
        });
        livreMenu.add(chargerButton);

        enregistrerButton.setText("Enregister");
        enregistrerButton.setEnabled(false);
        enregistrerButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                enregistrerButtonActionPerformed(evt);
            }
        });
        livreMenu.add(enregistrerButton);
        livreMenu.add(jSeparator1);

        analyserButton.setText("Analyser");
        analyserButton.setEnabled(false);
        analyserButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                analyserButtonActionPerformed(evt);
            }
        });
        livreMenu.add(analyserButton);
        livreMenu.add(jSeparator2);

        fermerLivreBtn.setText("Fermer");
        fermerLivreBtn.setEnabled(false);
        fermerLivreBtn.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                fermerLivreBtnActionPerformed(evt);
            }
        });
        livreMenu.add(fermerLivreBtn);

        quitterButton.setText("Quitter");
        quitterButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                quitterButtonActionPerformed(evt);
            }
        });
        livreMenu.add(quitterButton);

        jMenuBar1.add(livreMenu);

        editerMenu.setText("Editer");

        sectionsButton.setText("Sections");
        sectionsButton.setEnabled(false);
        sectionsButton.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                showSectionSelector(evt);
            }
        });
        sectionsButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                sectionsButtonActionPerformed(evt);
            }
        });
        sectionsButton.addVetoableChangeListener(new java.beans.VetoableChangeListener() {
            public void vetoableChange(java.beans.PropertyChangeEvent evt)throws java.beans.PropertyVetoException {
                sectionsButtonVetoableChange(evt);
            }
        });
        editerMenu.add(sectionsButton);

        enchainementsButton.setText("Enchainements");
        enchainementsButton.setEnabled(false);
        enchainementsButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                enchainementsButtonActionPerformed(evt);
            }
        });
        editerMenu.add(enchainementsButton);

        jMenuBar1.add(editerMenu);

        generationMenu.setText("Generation");

        genHTMLButton.setText("HTML");
        genHTMLButton.setEnabled(false);
        generationMenu.add(genHTMLButton);

        genImprimableButton.setText("Imprimable");
        genImprimableButton.setEnabled(false);
        generationMenu.add(genImprimableButton);

        jMenuBar1.add(generationMenu);

        setJMenuBar(jMenuBar1);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(graphPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(editionPanes, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(editionPanes, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
            .addComponent(graphPanel, javax.swing.GroupLayout.DEFAULT_SIZE, 631, Short.MAX_VALUE)
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void creerButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_creerButtonActionPerformed
        this.setActiveLivre(false);
        JPanel creationDialog = new JPanel();
        creationDialog.add(new JLabel("Auteur"));
        JTextField auteur = new JTextField(10);
        creationDialog.add(auteur);
        creationDialog.add(Box.createHorizontalStrut(15));
        creationDialog.add(new JLabel("Titre"));
        JTextField titre = new JTextField(10);
        creationDialog.add(titre);
        int result = JOptionPane.showConfirmDialog(this, 
                creationDialog, 
                "Créer un nouveau livre", 
                JOptionPane.OK_CANCEL_OPTION);
        
        if (result != JOptionPane.OK_OPTION)
            return;
        
        ILivre livre = LivreFactory.getLivre();
        livre.setTitre(titre.getText().trim());
        livre.setAuteur(auteur.getText().trim());
        this.setActiveLivre(true);
    }//GEN-LAST:event_creerButtonActionPerformed
    
    private void showSectionPanel() {
        ILivre livre = LivreFactory.getLivre();
        ISection initiale = livre.getSectionInitiale();
        this.sectionNom.setText(currentSection.getNom());
        this.sectionTexteTextArea.setText(currentSection.getTexte());
        
        if (initiale != null)
            this.sectionInitialeCheck.setSelected(
                initiale.getNom().equals(currentSection.getNom()));        
        
        DefaultListModel<ObjetLister> lm = new DefaultListModel<>();
        for (Integer objId : currentSection.listerObjets()) {
            String desc = livre.getGestObjet().getDescription(objId);
            lm.addElement(new ObjetLister(objId, desc));
        }
        this.sectionObjList.setModel(lm);
        this.editionPanes.setLayer(this.sectionPanel, this.editionPanes.highestLayer() + 1);
        this.sectionPanel.setVisible(true);
    }
    
    private void showEnchainementPanel() {
        ILivre livre = LivreFactory.getLivre();
        enchDepartLabel.setText(currentEnch[0].getNom());
        enchArriveeLabel.setText(currentEnch[1].getNom());

        DefaultListModel<ObjetLister> lm = new DefaultListModel<>();
        for (Integer objId : currentEnch[0].getConditions(currentEnch[1])) {
            String desc = livre.getGestObjet().getDescription(objId);
            lm.addElement(new ObjetLister(objId, desc));
        }
        this.enchCondList.setModel(lm);
        this.editionPanes.setLayer(this.enchainementPanel, this.editionPanes.highestLayer() + 1);
        this.enchainementPanel.setVisible(true);
    }
    
    private void quitterButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_quitterButtonActionPerformed
        System.exit(0);
    }//GEN-LAST:event_quitterButtonActionPerformed

    private void sectionsButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_sectionsButtonActionPerformed
        closeOpenEditionPanels();
        ILivre livre = LivreFactory.getLivre();
        
        final JComboBox sectionBox = new JComboBox();
        DefaultComboBoxModel<String> cbm = new DefaultComboBoxModel<>();
        for (ISection section : livre.listerSections())
            cbm.addElement(section.getNom());
        
        sectionBox.setModel(cbm);
        sectionBox.setEditable(true);
        sectionBox.setSelectedIndex(-1);
        JPanel myPanel = new JPanel();
        myPanel.add(new JLabel("Nom section: "));
        myPanel.add(sectionBox);
        int result = JOptionPane.showConfirmDialog(this, myPanel, 
               "Selectionner une section", JOptionPane.OK_CANCEL_OPTION);
        
        if (result != JOptionPane.OK_OPTION)
            return;
        
        String nomSection = (String) sectionBox.getSelectedItem();
        if (nomSection == null || nomSection.isEmpty()) {
            JOptionPane.showMessageDialog(this, "Aucun nom de section saisit", "Faute de saisie", JOptionPane.ERROR_MESSAGE);
            return;
        }
        
        this.currentSection = livre.creerSection(nomSection);
        graphViewer.addSection(currentSection);
        this.showSectionPanel();
        this.activateEnchainementsBtn();
    }//GEN-LAST:event_sectionsButtonActionPerformed

    private void sectionsButtonVetoableChange(java.beans.PropertyChangeEvent evt)throws java.beans.PropertyVetoException {//GEN-FIRST:event_sectionsButtonVetoableChange
        // TODO add your handling code here:
    }//GEN-LAST:event_sectionsButtonVetoableChange

    private void showSectionSelector(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_showSectionSelector
        
    }//GEN-LAST:event_showSectionSelector

    private void chargerButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_chargerButtonActionPerformed
        
        JFileChooser chooser = new JFileChooser();
        chooser.setFileFilter(new FileNameExtensionFilter("Fichier LDVH", "ldvh"));
        if (chooser.showOpenDialog(this) != JFileChooser.APPROVE_OPTION)
            return;
        
        setActiveLivre(false);
        ILoad loader = OutilsFactory.createCLoad();
        ILivre livre = loader.chargerFichier(chooser.getSelectedFile().getAbsolutePath());
        if (livre == null) {
            JOptionPane.showMessageDialog(this, 
                    "Un erreur est survenu lors du chargement du fichier", 
                    "Erreur", 
                    JOptionPane.ERROR_MESSAGE);
            return;
        }

        LivreFactory.loadLivre(livre);
        setActiveLivre(true);
    }//GEN-LAST:event_chargerButtonActionPerformed

    private void sectionInitialeCheckActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_sectionInitialeCheckActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_sectionInitialeCheckActionPerformed

    private void sectionAnnulerButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_sectionAnnulerButtonActionPerformed
        closeOpenEditionPanels();
    }//GEN-LAST:event_sectionAnnulerButtonActionPerformed

    private void sectionSupprimerBtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_sectionSupprimerBtnActionPerformed
        int choice = JOptionPane.showConfirmDialog(this, 
                "Supprimer la section " + currentSection.getNom() + "?", 
                "Confirmation suppression", 
                JOptionPane.OK_CANCEL_OPTION, 
                JOptionPane.QUESTION_MESSAGE);
        
        if (choice != JOptionPane.OK_OPTION)
            return;
        
        ILivre livre = LivreFactory.getLivre();
        graphViewer.removeSection(currentSection);
        
        for (Integer id : currentSection.listerObjets()) {
            livre.getGestObjet().supprimerObjet(id);
        
	        for (ISection dep : livre.listerSections()) {
	            for (ISection arr : dep.listerEnchainements()) {
	                dep.supprimerCondition(arr, id);
	            }
	        }
        }
        
        livre.supprimerSection(currentSection.getNom());
        this.activateEnchainementsBtn();
        closeOpenEditionPanels();
    }//GEN-LAST:event_sectionSupprimerBtnActionPerformed

    private void sectionValiderButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_sectionValiderButtonActionPerformed
        String texte = sectionTexteTextArea.getText().trim();
        if (texte.isEmpty()) {
            JOptionPane.showMessageDialog(this, 
                    "Le texte de section ne doit pas etre vide", 
                    "Texte vide", JOptionPane.WARNING_MESSAGE);
            return;
        }
        
        currentSection.setTexte(texte);
        if (sectionInitialeCheck.isSelected())
            LivreFactory.getLivre().setInitiale(currentSection.getNom());
        
        closeOpenEditionPanels();
    }//GEN-LAST:event_sectionValiderButtonActionPerformed

    private void sectionAjoutObjetBtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_sectionAjoutObjetBtnActionPerformed
        String desc = JOptionPane.showInputDialog(this, 
                "Saisir la description de l'objet", 
                "Création d'un objet", 
                JOptionPane.PLAIN_MESSAGE);
        
        if (desc == null)
            return;
        
        desc = desc.trim();      
        if (desc.isEmpty()) {
            JOptionPane.showMessageDialog(this, 
                    "La description saisie est vide", 
                    "Faute de saisie", 
                    JOptionPane.ERROR_MESSAGE);
            return;
        }
        DefaultListModel<ObjetLister> lm = (DefaultListModel<ObjetLister>) sectionObjList.getModel();
        
        for (Object o : lm.toArray())
            if (((ObjetLister)o).getDesc().equals(desc)) {
                JOptionPane.showMessageDialog(this, 
                    "Un objet ayant cette description est déjà présent dans la section", 
                    "Faute de saisie", 
                    JOptionPane.ERROR_MESSAGE);
                return;
            }
        
        int idObjet = LivreFactory.getLivre().getGestObjet().ajouterObjet(desc);
        currentSection.ajouterObjet(idObjet);
        lm.addElement(new ObjetLister(idObjet, desc));
    }//GEN-LAST:event_sectionAjoutObjetBtnActionPerformed

    private void sectionSupObjetBtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_sectionSupObjetBtnActionPerformed
        ILivre livre = LivreFactory.getLivre();
        DefaultListModel<ObjetLister> lm = (DefaultListModel<ObjetLister>) sectionObjList.getModel();
        ObjetLister objet = (ObjetLister) sectionObjList.getSelectedValue();
        if (objet == null) {
            JOptionPane.showMessageDialog(this, 
                    "Aucun objet selectionné", 
                    "Faute de saisie", 
                    JOptionPane.ERROR_MESSAGE);
            
            return;
        }
        
        int choice = JOptionPane.showConfirmDialog(this, 
                "Supprimer l'objet " + objet + "?",
                "Suppression objet", JOptionPane.OK_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE);
        
        if (choice != JOptionPane.OK_OPTION)
            return;
        
        currentSection.supprimerObjet(objet.getId());
        livre.getGestObjet().supprimerObjet(objet.getId());
        for (ISection dep : livre.listerSections()) {
            for (ISection arr : dep.listerEnchainements()) {
                dep.supprimerCondition(arr, objet.getId());
            }
        }
        lm.removeElement(objet);
        graphViewer.update();
    }//GEN-LAST:event_sectionSupObjetBtnActionPerformed

    private void enchainementsButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_enchainementsButtonActionPerformed
        ILivre livre = LivreFactory.getLivre();
        closeOpenEditionPanels();
        final JComboBox departBox = new JComboBox();
        JComboBox arriveeBox = new JComboBox();

        DefaultComboBoxModel<ISection> cbmDep = new DefaultComboBoxModel<>();
        final DefaultComboBoxModel<ISection> cbmArr = new DefaultComboBoxModel<>();
        for (ISection section : livre.listerSections()) {
            cbmDep.addElement(section);
            cbmArr.addElement(section);
        }
        
        cbmArr.removeElement(cbmDep.getElementAt(0));
        
        departBox.setModel(cbmDep);
        arriveeBox.setModel(cbmArr);

        JPanel myPanel = new JPanel();
        myPanel.add(new JLabel("Depart: "));
        myPanel.add(departBox);
        myPanel.add(Box.createHorizontalStrut(15)); // a spacer
        myPanel.add(new JLabel("Arrivée: "));
        myPanel.add(arriveeBox);
        departBox.addItemListener(new ItemListener() {
            ISection previous = (ISection) departBox.getSelectedItem();
            @Override
            public void itemStateChanged(ItemEvent e) {
                if (previous != null)
                    cbmArr.addElement(previous);

                ISection selDep = (ISection) e.getItem();
                cbmArr.removeElement(selDep);
                previous = selDep;
            }
        });
        
        int result = JOptionPane.showConfirmDialog(this, myPanel, 
               "Saisir les sections de depart et arrivée", JOptionPane.OK_CANCEL_OPTION);
        if (result != JOptionPane.OK_OPTION)
            return;
        
        ISection depart = (ISection) departBox.getSelectedItem();
        ISection arrivee = (ISection) arriveeBox.getSelectedItem();
        
        if (depart == null || arrivee == null) {
            JOptionPane.showMessageDialog(this, 
                    "Les sections saisies ne sont pas correctes", 
                    "Faute de saisie", 
                    JOptionPane.ERROR_MESSAGE);
            return;
        }
        
        depart.creerEnchainement(arrivee);
        currentEnch = new ISection[]{depart, arrivee};
        graphViewer.addEnchainement(currentEnch);
        this.showEnchainementPanel();
    }//GEN-LAST:event_enchainementsButtonActionPerformed

    private void enchAjoutCondBtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_enchAjoutCondBtnActionPerformed
        ILivre livre = LivreFactory.getLivre();
        DefaultListModel<ObjetLister> lm = (DefaultListModel<ObjetLister>) enchCondList.getModel();
        List<ObjetLister> allObjs = new ArrayList<>();
        
        for (Integer objId : livre.getGestObjet().listerObjets()) {
            String desc = livre.getGestObjet().getDescription(objId);
            ObjetLister ol = new ObjetLister(objId, desc);
            if ( ! lm.contains(ol))
                allObjs.add(ol);
        }
        
        if (allObjs.isEmpty()) {
            JOptionPane.showMessageDialog(this, "Aucun objet disponible", "Aucun objet", JOptionPane.WARNING_MESSAGE);
            return;
        }
        
        ObjetLister choice = (ObjetLister) JOptionPane.showInputDialog(this, 
                "Saisir l'objet à ajouter comme condition", 
                "Ajout d'une condition", 
                JOptionPane.PLAIN_MESSAGE, null, allObjs.toArray(), (Object) allObjs.get(0));
        
        if (choice == null)
            return;
        
        currentEnch[0].ajouterCondition(currentEnch[1], choice.getId());
        lm.addElement(choice);
        graphViewer.update();
    }//GEN-LAST:event_enchAjoutCondBtnActionPerformed

    private void enchSupCondBtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_enchSupCondBtnActionPerformed
        DefaultListModel<ObjetLister> lm = (DefaultListModel<ObjetLister>) enchCondList.getModel();
        ObjetLister objet = (ObjetLister) enchCondList.getSelectedValue();
        if (objet == null) {
            JOptionPane.showMessageDialog(this, 
                    "Aucune condition selectionné", 
                    "Faute de saisie", 
                    JOptionPane.ERROR_MESSAGE);
            
            return;
        }
        
        int choice = JOptionPane.showConfirmDialog(this, 
                "Supprimer la condition " + objet + "?",
                "Suppression condition", JOptionPane.OK_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE);
        
        if (choice != JOptionPane.OK_OPTION)
            return;
        
        currentEnch[0].supprimerCondition(currentEnch[1], objet.getId());
        lm.removeElement(objet);
        graphViewer.update();
    }//GEN-LAST:event_enchSupCondBtnActionPerformed

    private void enchSupprimerBtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_enchSupprimerBtnActionPerformed
        int choice = JOptionPane.showConfirmDialog(this, 
                "Supprimer l'enchainement " + currentEnch[0].getNom() + " -> " + currentEnch[1].getNom() + "?", 
                "Confirmation suppression", 
                JOptionPane.OK_CANCEL_OPTION, 
                JOptionPane.QUESTION_MESSAGE);
        
        if (choice != JOptionPane.OK_OPTION)
            return;
        
        currentEnch[0].supprimerEnchainement(currentEnch[1]);
        graphViewer.removeEnchainement(currentEnch);
        closeOpenEditionPanels();
    }//GEN-LAST:event_enchSupprimerBtnActionPerformed

    private void enchAnnulerButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_enchAnnulerButtonActionPerformed
        closeOpenEditionPanels();
    }//GEN-LAST:event_enchAnnulerButtonActionPerformed

    private void enchValiderButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_enchValiderButtonActionPerformed
        closeOpenEditionPanels();
    }//GEN-LAST:event_enchValiderButtonActionPerformed

    private void fermerLivreBtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_fermerLivreBtnActionPerformed
        setActiveLivre(false);
    }//GEN-LAST:event_fermerLivreBtnActionPerformed

    private void enregistrerButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_enregistrerButtonActionPerformed
        JFileChooser chooser = new JFileChooser();
        chooser.setFileFilter(new FileNameExtensionFilter("Fichier LDVH", "ldvh"));
        if (chooser.showSaveDialog(this) != JFileChooser.APPROVE_OPTION)
            return;
         
        ISave saver = OutilsFactory.createCSave(LivreFactory.getLivre());
        saver.saveLivre(chooser.getSelectedFile().getAbsolutePath());
    }//GEN-LAST:event_enregistrerButtonActionPerformed

    private void analyserButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_analyserButtonActionPerformed
        ILivre livre = LivreFactory.getLivre();
        IAnalyseGraphe analyzer = OutilsFactory.createCAnalyseGraphe(livre);
        List<ISection> unreachable = new ArrayList<>();
        List<ISection[]> insatisfiables = new ArrayList<>();
        if (analyzer.analyser()) {
            JOptionPane.showMessageDialog(this, "Le livre n'as aucun probleme");
        }
        else {
            for (String problem : analyzer.getResultatsAnalyse()) {
                String msg[] = problem.split(":");
                switch(msg[0]) {
                    case "section":
                        unreachable.add(livre.getSection(msg[1]));
                        break;
                    case "enchainement":
                        ISection dep = livre.getSection(msg[1]);
                        ISection arr = livre.getSection(msg[2]);
                        insatisfiables.add(new ISection[]{dep, arr});
                        break;
                }
            }
        }
        this.graphViewer.setUnreachable(unreachable);
        this.graphViewer.setInsatisfiable(insatisfiables);
    }//GEN-LAST:event_analyserButtonActionPerformed

    private void setActiveLivre(boolean enable) {
        if (enable) {
            ILivre livre = LivreFactory.getLivre();
            graphViewer.init();
            this.setTitle("LDVH: " + livre.getTitre() + " - " + livre.getAuteur());
            this.activateEnchainementsBtn();
        }
        else {
            graphViewer.reset();
            LivreFactory.destroyLivre();
            this.setTitle("LDVH");
            enchainementsButton.setEnabled(false);
            closeOpenEditionPanels();
        }

        sectionsButton.setEnabled(enable);
        enregistrerButton.setEnabled(enable);
        analyserButton.setEnabled(enable);
        genHTMLButton.setEnabled(enable);
        genImprimableButton.setEnabled(enable);
        fermerLivreBtn.setEnabled(enable);
    }
    
    private void activateEnchainementsBtn() {
        enchainementsButton.setEnabled(LivreFactory.getLivre().listerSections().length >= 2);        
    }
    
    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(LdvhIHM.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(LdvhIHM.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(LdvhIHM.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(LdvhIHM.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            @Override
            public void run() {
                new LdvhIHM().setVisible(true);
            }
        });
    }
    
    private ISection currentSection;
    private ISection currentEnch[];
    private final LdvhGraphViewer graphViewer;
    
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JMenuItem analyserButton;
    private javax.swing.JMenuItem chargerButton;
    private javax.swing.JMenuItem creerButton;
    private javax.swing.JMenu editerMenu;
    private javax.swing.JLayeredPane editionPanes;
    private javax.swing.JButton enchAjoutCondBtn;
    private javax.swing.JButton enchAnnulerButton;
    private javax.swing.JLabel enchArriveeLabel;
    private javax.swing.JLabel enchArrowLabel;
    private javax.swing.JList enchCondList;
    private javax.swing.JPanel enchCondsPanel;
    private javax.swing.JLabel enchDepartLabel;
    private javax.swing.JButton enchSupCondBtn;
    private javax.swing.JButton enchSupprimerBtn;
    private javax.swing.JButton enchValiderButton;
    private javax.swing.JPanel enchainementPanel;
    private javax.swing.JMenuItem enchainementsButton;
    private javax.swing.JMenuItem enregistrerButton;
    private javax.swing.JMenuItem fermerLivreBtn;
    private javax.swing.JMenuItem genHTMLButton;
    private javax.swing.JMenuItem genImprimableButton;
    private javax.swing.JMenu generationMenu;
    private javax.swing.JPanel graphPanel;
    private javax.swing.JMenuBar jMenuBar1;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JPopupMenu.Separator jSeparator1;
    private javax.swing.JPopupMenu.Separator jSeparator2;
    private javax.swing.JMenu livreMenu;
    private javax.swing.JMenuItem quitterButton;
    private javax.swing.JButton sectionAjoutObjetBtn;
    private javax.swing.JButton sectionAnnulerButton;
    private javax.swing.JCheckBox sectionInitialeCheck;
    private javax.swing.JLabel sectionNom;
    private javax.swing.JList sectionObjList;
    private javax.swing.JPanel sectionObjetsPanel;
    private javax.swing.JPanel sectionPanel;
    private javax.swing.JButton sectionSupObjetBtn;
    private javax.swing.JButton sectionSupprimerBtn;
    private javax.swing.JPanel sectionTextePanel;
    private javax.swing.JTextArea sectionTexteTextArea;
    private javax.swing.JButton sectionValiderButton;
    private javax.swing.JMenuItem sectionsButton;
    // End of variables declaration//GEN-END:variables

    private void closeOpenEditionPanels() {
        if (enchainementPanel.isVisible() || sectionPanel.isVisible()) {
            graphViewer.update();
            this.editionPanes.setLayer(enchainementPanel, 0);
            this.editionPanes.setLayer(sectionPanel, 0);            
            enchainementPanel.setVisible(false);
            sectionPanel.setVisible(false);
            currentEnch = null;
            currentSection = null;
        }
     }
}
